<template>
  <j-modal
      :title="title"
      :width="width"
      :visible="visible"
      switchFullscreen
      @ok="close"
      :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
      @cancel="close"
      cancelText="关闭">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <!--        <a-row :gutter="24">-->
        <!--          <a-col :span="6">-->
        <!--            <a-form-model-item label="姓名">-->
        <!--              <j-input v-model="queryParam.fullName"/>-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <!--          <a-col :span="6">-->
        <!--            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">-->
        <!--              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>-->
        <!--              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>-->
        <!--            </span>-->
        <!--          </a-col>-->
        <!--        </a-row>-->
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->
      <a-button @click="showAddForm" type="primary" icon="plus">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
      <!--        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项-->
      <!--        <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
      <!--      </div>-->

      <a-table
          ref="table"
          size="middle"
          :scroll="{x:true}"
          :bordered="false"
          rowKey="user.id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          class="j-table-force-nowrap"
          @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
              v-else
              :ghost="true"
              type="primary"
              icon="download"
              size="small"
              @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <!--          <a-divider type="vertical"/>-->
          <!--          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
          <!--            <a>删除</a>-->
          <!--          </a-popconfirm>-->
        </span>

      </a-table>
    </div>

    <hc-site-address-details-modal ref="modalForm" @ok="modalFormOk"></hc-site-address-details-modal>
  </j-modal>
</template>

<script>

import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import {downFile} from "@api/manage";
import HcSiteAddressDetailsModal from './modules/HcSiteAddressDetailsModal'

export default {
  name: 'HcSiteAddressListModal',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    HcSiteAddressDetailsModal

  },
  data() {
    return {
      title: '',
      width: 1200,
      visible: false,
      disableSubmit: false,
      description: '地址明细',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        // {
        //   title:'微信OPENID',
        //   align:"center",
        //   dataIndex: 'openId'
        // },
        {
          title: '大厦名',
          align: "center",
          dataIndex: 'addressName'
        },
        {
          title: '供应地址',
          align: "center",
          dataIndex: 'supplyAddress',
          customRender: function (t, r, index) {
            let val = '';

            try {
              let parse = JSON.parse(t);

              if (parse != null && parse.length > 0) {
                parse.forEach(item => {
                  val += item.name + '(' + item.code + ')' + '；';
                });
              }
            } catch (e) {

            }

            return val;
          }
        },
        {
          title: '佣金',
          align: "center",
          dataIndex: 'commission'
        },
        {
          title: '骑手姓名',
          align: "center",
          dataIndex: 'nameRider_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          width: 147,
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        list: "/hc/hcSiteAddressDetails/list",
        delete: "/hc/hcSiteAddressDetails/delete",
        deleteBatch: "/hc/hcSiteAddressDetails/deleteBatch",
      },
      dictOptions: {},
      superFieldList: [],
      disableMixinCreated: true,
      record: {},
    }
  },
  created() {

  },
  methods: {
    showAddForm() {
      this.$refs.modalForm.show(this.queryParam.siteId)
    },
    searchReset() {
      this.queryParam = {};
      this.queryParam.siteId = this.record.id;
      this.loadData(1);
    },
    open(record) {
      this.record = record;
      this.queryParam.siteId = this.record.id;
      this.loadData();
      this.visible = true
    },
    close() {
      this.visible = false;
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>